package com.wangdao.wechatmall.service.admin;

import com.wangdao.wechatmall.bean.pojo.System;
import com.wangdao.wechatmall.bean.pojo.SystemExample;
import com.wangdao.wechatmall.bean.vo.admin.ConfigMallVO;
import com.wangdao.wechatmall.bean.vo.admin.ConfigOrderVO;
import com.wangdao.wechatmall.bean.vo.admin.ConfigWxVO;
import com.wangdao.wechatmall.bean.vo.admin.ExpressVO;
import com.wangdao.wechatmall.mapper.SystemMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ConfigServiceImpl
 * created by feng on 7/9/21
 */

@Service
public class ConfigServiceImpl implements ConfigService {
    @Autowired
    SystemMapper systemMapper;

    @Override
    public ExpressVO expressGet() {
        //find cskaoyan_mall_express_freight_value
        SystemExample systemExample = new SystemExample();
        SystemExample.Criteria criteria = systemExample.createCriteria();
        criteria.andKeyNameEqualTo("cskaoyan_mall_express_freight_value");

        List<System> freight_value = systemMapper.selectByExample(systemExample);


        //find cskaoyan_mall_express_freight_min
        SystemExample systemExample1 = new SystemExample();
        SystemExample.Criteria criteria1 = systemExample1.createCriteria();
        criteria1.andKeyNameEqualTo("cskaoyan_mall_express_freight_min");

        List<System> freight_min = systemMapper.selectByExample(systemExample1);

        ExpressVO expressVO = new ExpressVO();

        String freightGetValue = null;
        //set freight_value
        for (System fValue : freight_value) {
            freightGetValue = fValue.getKeyValue();
        }

        String minGetValue = null;
        //set freight_min
        for (System minValue : freight_min) {
            minGetValue = minValue.getKeyValue();
        }

        expressVO.setCskaoyanmallExpressFreightValue(freightGetValue);
        expressVO.setCskaoyanmallExpressFreightMin(minGetValue);

        return expressVO;
    }

    @Override
    public ConfigOrderVO orderGet() {
        //get cskaoyan_mall_order_comment
        SystemExample systemExample = new SystemExample();
        SystemExample.Criteria criteria = systemExample.createCriteria();
        criteria.andKeyNameEqualTo("cskaoyan_mall_order_comment");
        List<System> systems = systemMapper.selectByExample(systemExample);

        String comment = null;
        for (System s1 : systems) {
            comment = s1.getKeyValue();
        }

        //get cskaoyan_mall_order_unpaid
        SystemExample systemExample1 = new SystemExample();
        SystemExample.Criteria criteria1 = systemExample1.createCriteria();
        criteria1.andKeyNameEqualTo("cskaoyan_mall_order_unpaid");
        List<System> systems1 = systemMapper.selectByExample(systemExample1);

        String unpaid = null;
        for (System s2 : systems1) {
            unpaid = s2.getKeyValue();
        }

        //get cskaoyan_mall_order_unconfirm
        SystemExample systemExample2 = new SystemExample();
        SystemExample.Criteria criteria2 = systemExample2.createCriteria();
        criteria2.andKeyNameEqualTo("cskaoyan_mall_order_unconfirm");
        List<System> systems2 = systemMapper.selectByExample(systemExample2);

        String unconfirm = null;
        for (System s2 : systems2) {
            unconfirm = s2.getKeyValue();
        }
        // return configOrderVO
        ConfigOrderVO configOrderVO = new ConfigOrderVO();
        configOrderVO.setCskaoyanmallOrderComment(comment);
        configOrderVO.setCskaoyanmallOrderUnpaid(unpaid);
        configOrderVO.setCskaoyanmallOrderUnconfirm(unconfirm);

        return configOrderVO;
    }

    @Override
    public ConfigWxVO wxGet() {
        //get  cskaoyan_mall_wx_catlog_list
        SystemExample systemExapmpl1 = new SystemExample();
        SystemExample.Criteria criteria1 = systemExapmpl1.createCriteria();
        criteria1.andKeyNameEqualTo("cskaoyan_mall_wx_catlog_list");
        List<System> systems1 = systemMapper.selectByExample(systemExapmpl1);

        String catlogList = null;
        for (System s1 : systems1) {
            catlogList = s1.getKeyValue();
        }


        //get cskaoyan_mall_wx_catlog_goods
        SystemExample systemExapmpl2 = new SystemExample();
        SystemExample.Criteria criteria2 = systemExapmpl2.createCriteria();
        criteria2.andKeyNameEqualTo("cskaoyan_mall_wx_catlog_goods");
        List<System> systems2 = systemMapper.selectByExample(systemExapmpl2);

        String catlogGood = null;
        for (System s1 : systems2) {
            catlogGood = s1.getKeyValue();
        }

        //get cskaoyan_mall_wx_index_brand
        SystemExample systemExapmpl3 = new SystemExample();
        SystemExample.Criteria criteria3 = systemExapmpl3.createCriteria();
        criteria3.andKeyNameEqualTo("cskaoyan_mall_wx_index_brand");
        List<System> systems3 = systemMapper.selectByExample(systemExapmpl3);

        String indexBrand = null;
        for (System s1 : systems3) {
            indexBrand = s1.getKeyValue();
        }


        //get cskaoyan_mall_wx_index_hot
        SystemExample systemExapmpl4 = new SystemExample();
        SystemExample.Criteria criteria4 = systemExapmpl4.createCriteria();
        criteria4.andKeyNameEqualTo("cskaoyan_mall_wx_index_hot");
        List<System> systems4 = systemMapper.selectByExample(systemExapmpl4);

        String indexHot = null;
        for (System s1 : systems4) {
            indexHot = s1.getKeyValue();
        }

        //get cskaoyan_mall_wx_index_new
        SystemExample systemExapmpl5 = new SystemExample();
        SystemExample.Criteria criteria5 = systemExapmpl5.createCriteria();
        criteria5.andKeyNameEqualTo("cskaoyan_mall_wx_index_new");
        List<System> systems5 = systemMapper.selectByExample(systemExapmpl5);

        String indexNew = null;
        for (System s1 : systems5) {
            indexNew = s1.getKeyValue();
        }


        //get cskaoyan_mall_wx_index_topic
        SystemExample systemExapmpl6 = new SystemExample();
        SystemExample.Criteria criteria6 = systemExapmpl6.createCriteria();
        criteria6.andKeyNameEqualTo("cskaoyan_mall_wx_index_topic");
        List<System> systems6 = systemMapper.selectByExample(systemExapmpl6);

        String indexTopic = null;
        for (System s1 : systems6) {
            indexTopic = s1.getKeyValue();
        }

        //get cskaoyan_mall_wx_share
        SystemExample systemExapmpl7 = new SystemExample();
        SystemExample.Criteria criteria7 = systemExapmpl7.createCriteria();
        criteria7.andKeyNameEqualTo("cskaoyan_mall_wx_share");
        List<System> systems7 = systemMapper.selectByExample(systemExapmpl7);

        String wxShare = null;
        for (System s1 : systems7) {
            wxShare = s1.getKeyValue();
        }


        //return configWxVO
        ConfigWxVO configWxVO = new ConfigWxVO();
        configWxVO.setCskaoyanmallWxCatlogList(catlogList);
        configWxVO.setCskaoyanmallWxCatlogGoods(catlogGood);
        configWxVO.setCskaoyanmallWxIndexBrand(indexBrand);
        configWxVO.setCskaoyanmallWxIndexHot(indexHot);
        configWxVO.setCskaoyanmallWxIndexNew(indexNew);
        configWxVO.setCskaoyanmallWxIndexTopic(indexTopic);
        configWxVO.setCskaoyanmallWxShare(wxShare);

        return configWxVO;
    }

    @Override
    public Integer wxPost(ConfigWxVO configWxVO) {

        int affectedRow = 0;
        //wx_share
        SystemExample systemExample1 = new SystemExample();
        SystemExample.Criteria criteria1 = systemExample1.createCriteria();
        criteria1.andKeyNameEqualTo("cskaoyan_mall_wx_share");
        System system1 = new System();
        system1.setKeyValue(configWxVO.getCskaoyanmallWxShare());
        int i1 = systemMapper.updateByExampleSelective(system1, systemExample1);
        affectedRow += i1;

        // catlog_Good
        SystemExample systemExample2 = new SystemExample();
        SystemExample.Criteria criteria2 = systemExample2.createCriteria();
        criteria2.andKeyNameEqualTo("cskaoyan_mall_wx_catlog_goods");
        System system2 = new System();
        system2.setKeyValue(configWxVO.getCskaoyanmallWxCatlogGoods());
        int i2 = systemMapper.updateByExampleSelective(system2, systemExample2);
        affectedRow += i2;


        // cskaoyan_mall_wx_catlog_list
        SystemExample systemExample3 = new SystemExample();
        SystemExample.Criteria criteria3 = systemExample3.createCriteria();
        criteria3.andKeyNameEqualTo("cskaoyan_mall_wx_catlog_list");
        System system3 = new System();
        system3.setKeyValue(configWxVO.getCskaoyanmallWxCatlogList());
        int i3 = systemMapper.updateByExampleSelective(system3, systemExample3);
        affectedRow += i3;


        // cskaoyan_mall_wx_index_brand
        SystemExample systemExample4 = new SystemExample();
        SystemExample.Criteria criteria4 = systemExample4.createCriteria();
        criteria4.andKeyNameEqualTo("cskaoyan_mall_wx_index_brand");
        System system4 = new System();
        system4.setKeyValue(configWxVO.getCskaoyanmallWxIndexBrand());
        int i4 = systemMapper.updateByExampleSelective(system4, systemExample4);
        affectedRow += i4;


        // cskaoyan_mall_wx_index_hot
        SystemExample systemExample5 = new SystemExample();
        SystemExample.Criteria criteria5 = systemExample5.createCriteria();
        criteria5.andKeyNameEqualTo("cskaoyan_mall_wx_index_hot");
        System system5 = new System();
        system5.setKeyValue(configWxVO.getCskaoyanmallWxIndexHot());
        int i5 = systemMapper.updateByExampleSelective(system5, systemExample5);
        affectedRow += i5;

        // cskaoyan_mall_wx_index_new
        SystemExample systemExample6 = new SystemExample();
        SystemExample.Criteria criteria6 = systemExample6.createCriteria();
        criteria6.andKeyNameEqualTo("cskaoyan_mall_wx_index_new");
        System system6 = new System();
        system6.setKeyValue(configWxVO.getCskaoyanmallWxIndexNew());
        int i6 = systemMapper.updateByExampleSelective(system6, systemExample6);
        affectedRow += i6;


        // cskaoyan_mall_wx_index_topic
        SystemExample systemExample7 = new SystemExample();
        SystemExample.Criteria criteria7 = systemExample7.createCriteria();
        criteria7.andKeyNameEqualTo("cskaoyan_mall_wx_index_topic");
        System system7 = new System();
        system7.setKeyValue(configWxVO.getCskaoyanmallWxIndexTopic());
        int i7 = systemMapper.updateByExampleSelective(system7, systemExample7);
        affectedRow += i7;

        return affectedRow;
    }

    @Override
    public ConfigMallVO mallGet() {
        //cskaoyanmall_mall_name
        SystemExample systemExample1 = new SystemExample();
        SystemExample.Criteria criteria1 = systemExample1.createCriteria();
        criteria1.andKeyNameEqualTo("cskaoyan_mall_mall_name");
        List<System> systems1 = systemMapper.selectByExample(systemExample1);

        String mallname = null;
        for (System s1 : systems1) {
            mallname = s1.getKeyValue();
        }

        //cskaoyanmall_mall_qq
        SystemExample systemExample2 = new SystemExample();
        SystemExample.Criteria criteria2 = systemExample2.createCriteria();
        criteria2.andKeyNameEqualTo("cskaoyan_mall_mall_qq");
        List<System> systems2 = systemMapper.selectByExample(systemExample2);

        String mallQq = null;
        for (System s1 : systems2) {
            mallQq = s1.getKeyValue();
        }

        //cskaoyanmall_mall_phone
        SystemExample systemExample3 = new SystemExample();
        SystemExample.Criteria criteria3 = systemExample3.createCriteria();
        criteria3.andKeyNameEqualTo("cskaoyan_mall_mall_phone");
        List<System> systems3 = systemMapper.selectByExample(systemExample3);

        String mallPhone = null;
        for (System s1 : systems3) {
            mallPhone = s1.getKeyValue();
        }

        //cskaoyanmall_mall_address
        SystemExample systemExample4 = new SystemExample();
        SystemExample.Criteria criteria4 = systemExample4.createCriteria();
        criteria4.andKeyNameEqualTo("cskaoyan_mall_mall_address");
        List<System> systems4 = systemMapper.selectByExample(systemExample4);

        String mallAddress = null;
        for (System s1 : systems4) {
            mallAddress = s1.getKeyValue();
        }

        //return configMallVO
        ConfigMallVO configMallVO = new ConfigMallVO();
        configMallVO.setCskaoyanmallMallName(mallname);
        configMallVO.setCskaoyanmallMallQq(mallQq);
        configMallVO.setCskaoyanmallMallPhone(mallPhone);
        configMallVO.setCskaoyanmallMallAddress(mallAddress);

        return configMallVO;
    }

    @Override
    public Integer mallPost(ConfigMallVO configMallVO) {
        // affectedRow
        int affectedRow = 0;

        // cskaoyanmall_mall_name
        SystemExample systemExample1 = new SystemExample();
        SystemExample.Criteria criteria1 = systemExample1.createCriteria();
        criteria1.andKeyNameEqualTo("cskaoyan_mall_mall_name");
        System system1 = new System();
        system1.setKeyValue(configMallVO.getCskaoyanmallMallName());
        int i1 = systemMapper.updateByExampleSelective(system1, systemExample1);
        affectedRow += i1;

        //cskaoyanmall_mall_qq
        SystemExample systemExample2 = new SystemExample();
        SystemExample.Criteria criteria2 = systemExample2.createCriteria();
        criteria2.andKeyNameEqualTo("cskaoyan_mall_mall_qq");
        System system2 = new System();
        system2.setKeyValue(configMallVO.getCskaoyanmallMallQq());
        int i2 = systemMapper.updateByExampleSelective(system2, systemExample2);
        affectedRow += i2;

        //cskaoyanmall_mall_phone
        SystemExample systemExample3 = new SystemExample();
        SystemExample.Criteria criteria3 = systemExample3.createCriteria();
        criteria3.andKeyNameEqualTo("cskaoyan_mall_mall_phone");
        System system3 = new System();
        system3.setKeyValue(configMallVO.getCskaoyanmallMallPhone());
        int i3 = systemMapper.updateByExampleSelective(system3, systemExample3);
        affectedRow += i3;

        //skaoyanmall_mall_address
        SystemExample systemExample4 = new SystemExample();
        SystemExample.Criteria criteria4 = systemExample4.createCriteria();
        criteria4.andKeyNameEqualTo("cskaoyan_mall_mall_address");
        System system4 = new System();
        system4.setKeyValue(configMallVO.getCskaoyanmallMallAddress());
        int i4 = systemMapper.updateByExampleSelective(system4, systemExample4);
        affectedRow += i4;


        return affectedRow;
    }

    @Override
    public Integer expressPost(ExpressVO expressVo) {
        int affectedRow = 0;

        //cskaoyan_mall_express_freight_value
        SystemExample systemExample1 = new SystemExample();
        SystemExample.Criteria criteria1 = systemExample1.createCriteria();
        criteria1.andKeyNameEqualTo("cskaoyan_mall_express_freight_value");
        System system1 = new System();
        system1.setKeyValue(expressVo.getCskaoyanmallExpressFreightValue());
        int i1 = systemMapper.updateByExampleSelective(system1, systemExample1);
        affectedRow += i1;

        //cskaoyan_mall_express_freight_min
        SystemExample systemExample2 = new SystemExample();
        SystemExample.Criteria criteria2 = systemExample2.createCriteria();
        criteria2.andKeyNameEqualTo("cskaoyan_mall_express_freight_min");
        System system2 = new System();
        system2.setKeyValue(expressVo.getCskaoyanmallExpressFreightMin());
        int i2 = systemMapper.updateByExampleSelective(system2, systemExample2);
        affectedRow += i2;

        return affectedRow;
    }

    @Override
    public Integer orderPost(ConfigOrderVO configOrderVO) {
        int affectedRow = 0;

        //cskaoyan_mall_order_unconfirm
        SystemExample systemExample1 = new SystemExample();
        SystemExample.Criteria criteria1 = systemExample1.createCriteria();
        criteria1.andKeyNameEqualTo("cskaoyan_mall_order_unconfirm");
        System system1 = new System();
        system1.setKeyValue(configOrderVO.getCskaoyanmallOrderUnconfirm());
        int i1 = systemMapper.updateByExampleSelective(system1, systemExample1);
        affectedRow += i1;

        //cskaoyan_mall_order_unpaid
        SystemExample systemExample2 = new SystemExample();
        SystemExample.Criteria criteria2 = systemExample2.createCriteria();
        criteria2.andKeyNameEqualTo("cskaoyan_mall_order_unpaid");
        System system2 = new System();
        system2.setKeyValue(configOrderVO.getCskaoyanmallOrderUnpaid());
        int i2 = systemMapper.updateByExampleSelective(system2, systemExample2);
        affectedRow += i2;

        //cskaoyan_mall_order_comment
        SystemExample systemExample3 = new SystemExample();
        SystemExample.Criteria criteria3 = systemExample3.createCriteria();
        criteria3.andKeyNameEqualTo("cskaoyan_mall_order_comment");
        System system3 = new System();
        system3.setKeyValue(configOrderVO.getCskaoyanmallOrderComment());
        int i3 = systemMapper.updateByExampleSelective(system3, systemExample3);
        affectedRow += i3;

        return affectedRow;
    }
}